package org.example.distributed_lock;

import org.apache.zookeeper.KeeperException;

public class DistributedLockTest {
    public static void main(String[] args) {
        final DistributedLock lock1 = new DistributedLock();
        final DistributedLock lock2 = new DistributedLock();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    lock1.zkLock();
                    Thread.sleep(3 * 1000);
                    lock1.zkUnlock();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                } catch (KeeperException e) {
                    throw new RuntimeException(e);
                }

            }
        }).start();
        new Thread(new Runnable() {
            @Override
            public void run() {
                try {
                    lock2.zkLock();
                    Thread.sleep(3 * 1000);
                    lock2.zkUnlock();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                } catch (KeeperException e) {
                    throw new RuntimeException(e);
                }

            }
        }).start();
    }
}
